package com.ruoyi.project.relation.mapper.provider;

import com.ruoyi.project.relation.domain.dto.BusinessRelationDO;
import com.ruoyi.project.relation.domain.qo.BusinessLinkQO;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.jdbc.SQL;

/**
 *
 **/
public class BusinessLinkSqlProvider {

    String columns="self_link_flag as selfLinkFlag,business_link_id as businessLinkId, source_owner_id as sourceOwnerId, source_owner_name as sourceOwnerName, source_owner_type as sourceOwnerType," +
            " ancestor_owner_id as ancestorOwnerId, level, ancestor_owner_name as ancestorOwnerName, create_user_id as createUserId, ancestor_owner_type as ancestorOwnerType, create_time as createTime, del_flag as delFlag";

    String tableName="business_link";

    public String selectParentTreeList(final BusinessLinkQO businessRelationDO){
        String sql;
        sql =new SQL(){{
            SELECT(columns);
            FROM(tableName);
            if(!ObjectUtils.allNotNull(businessRelationDO.getSourceOwnerId(),businessRelationDO.getSourceOwnerName())){
                throw new RuntimeException("selectParentTreeByBusinessRelationDO 任何一个不能为 null");
            }
            if(businessRelationDO.getSelfLinkFlag()!=null){
                WHERE("self_link_flag = #{selfLinkFlag}");
            }
//            WHERE("self_link_flag = 0");
//            if (inventoryBom.getOwnerId()!=null) {
                WHERE("source_owner_id = #{sourceOwnerId}");
//            WHERE("ancestor_owner_id = #{ownerId}");
//            }
//            if (inventoryBom.getOwnerName()!=null) {
                WHERE("source_owner_name = #{sourceOwnerName}");
//            WHERE("ancestor_owner_name = #{ownerName}");
//            }
            //获取父级树不需要类型
//            if (inventoryBom.getInventoryBomId()!=null) {
//                WHERE("source_owner_type = #{sourceOwnerType}");
//            WHERE("ancestor_owner_type = #{ownerType}");
//            }
            //按照级别排序
            ORDER_BY("level asc");
        }}.toString();
        return sql;
    }

}
